<?php
/**
 * @title 
 * @author start2004
 */

/**
 * @url http://127.0.0.1/leetcode/202010/2020.10.28_2.php
 */
if(!isset($_GET["key"])){
?>
    <video preload="auto" autoplay="true" webkit-playsinline="" playsinline="" x-webkit-airplay="allow" x5-video-orientation="landscape" x5-mse-live-streaming="" src="blob:http://127.0.0.1/leetcode/202010/2020.10.28_2.php?key=1" style="width: 500px; height: 350px;"></video>

    <!--<video id="video_player_id" width="660" height="364" controls="controls"></video>-->

    <script language="JavaScript">
        // function revokeUrl(url) {
        //     window.URL.revokeObjectURL(url);
        // }
        // /// 请注意 底下的 video_player 为你html video标签里面的 id
        // window.onload = function(){
        //     //创建XMLHttpRequest对象
        //     var xhr = new XMLHttpRequest();
        //     var url = "http://127.0.0.1/leetcode/202010/2020.10.28_2.php?key=2020"; // 这里的url为你的服务端地址
        //     //配置请求方式、请求地址以及是否同步
        //     xhr.open('POST', url, true);
        //     //设置请求结果类型为blob
        //     xhr.responseType = 'blob';
        //     //请求成功回调函数
        //     xhr.onload = function (e) {
        //         if (this.status == 200) {//请求成功
        //             //获取blob对象
        //             var blob = this.response;
        //             var video = document.getElementById('video_player');
        //             //获取blob对象地址，并把值赋给容器
        //             video.onload = function(e) {
        //                 window.URL.revokeObjectURL(video.src);
        //             };
        //             var obj_url = window.URL.createObjectURL(blob);
        //             video.src = obj_url;
        //             //video.play();
        //
        //         }
        //     };
        //     xhr.send();
        // }
    </script>

<?php
    die();
} else {}

$filePath = "/tmp/1.mp4";
@ob_end_clean();
ob_start();

$handler = fopen($filePath, "r+b");
$fileSize = filesize($filePath);

Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: {$fileSize}");
Header("Content-Disposition: attachment; filename=" . basename($filePath));

echo fread($handler, $fileSize);
fclose($handler);
ob_end_flush();